package com.hwc.demo.springcloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.hwc.demo.springcloud.entity.Dept;

@RestController
public class DeptController_consumer {
	//private static final String REST_URL_PREFIX = "http://localhost:8081";
	private static final String REST_URL_PREFIX = "http://SPRINGCLOUD-PROVIDER-DEPT"; //注册中心显示的应用名
	@Autowired
	RestTemplate restTemplate;
	
	@PostMapping("/consumer/dept")
	public int add (Dept reqDo) {
		
		return restTemplate.postForObject(REST_URL_PREFIX+"/dept", reqDo, Integer.class);
	}

	@GetMapping("/consumer/dept/{id}")
	public Dept get(@PathVariable Long id) {
		
		return restTemplate.getForObject(REST_URL_PREFIX+"/dept/"+id, Dept.class);
	}

	@GetMapping("/consumer/dept")
	public List<Dept> list() {
		
		return restTemplate.getForObject(REST_URL_PREFIX+"/dept", List.class);
	}
}
